// 导入 mongoose
const mongoose = require('mongoose')

// 创建文档的结构对象
// 设置集合中文档的属性以及属性值的类型
const UserSchema = new mongoose.Schema({
  username: {
    type: String,
    required: true
  },
  password: {
    type: String,
    required: true
  },
  role_id: {
    type: Number,
    default: 301
  },
  avatar: {
    type: Buffer,
    require: true
  },
  contentType: {
    type: String,
    require: true
  },
  state: {
    type: Number,
    default: 1
  },
  create_time: { type: Date }
})
// 创建模型对象
// 模型对象是对文档操作的封装对象
const UserModel = mongoose.model('user', UserSchema)

// 暴露模型对象
module.exports = UserModel
